package com.zac.basicAOP;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class UserDao {

	private Map<String, String> map = new HashMap<String, String>();
	
	public UserDao(){
		map.put("admin", "security");
		map.put("test", "123456");
	}
	
	public void create(String username, String password){
		if( map.containsValue(username))
				throw new RuntimeException("User exist!");
		map.put(username, password);
	}
	
	public void login(String username, String password){
		String pw = map.get(username);
		if( pw == null || !pw.equals(password) ){
			throw new RuntimeException("Login failed.");
		}
	}
	
	public void print(){
		System.out.println("User list:");
		Set<String> keySet = map.keySet();
		for(String key : keySet){
			System.out.println(key);
		}
	}
	
}
